package com.ruoyi.business.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.collection.CollectionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.business.domain.Alarmdatareal;
import com.ruoyi.business.service.IAlarmdatarealService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 报警实时记录Controller
 *
 * @author DL
 * @date 2025-07-02
 */
@RestController
@RequestMapping("/alarmdatareal")
public class AlarmdatarealController extends BaseController
{
    @Autowired
    private IAlarmdatarealService alarmdatarealService;

    /**
     * 查询报警实时记录列表
     */
    //@RequiresPermissions("business:alarmdatareal:list")
    @GetMapping("/list")
    public TableDataInfo list(Alarmdatareal alarmdatareal)
    {
        startPage();
        List<Alarmdatareal> list = alarmdatarealService.selectAlarmdatarealList(alarmdatareal);
        return getDataTable(list);
    }

    /**
     * 导出报警实时记录列表
     */
    //@RequiresPermissions("business:alarmdatareal:export")
    @Log(title = "报警实时记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Alarmdatareal alarmdatareal)
    {
        List<Alarmdatareal> list = alarmdatarealService.selectAlarmdatarealList(alarmdatareal);
        ExcelUtil<Alarmdatareal> util = new ExcelUtil<Alarmdatareal>(Alarmdatareal.class);
        util.exportExcel(response, list, "报警实时记录数据");
    }

    /**
     * 获取报警实时记录详细信息
     */
    //@RequiresPermissions("business:alarmdatareal:query")
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") Long ID)
    {
        return success(alarmdatarealService.selectAlarmdatarealByID(ID));
    }

    /**
     * 新增报警实时记录
     */
    //@RequiresPermissions("business:alarmdatareal:add")
    @Log(title = "报警实时记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Alarmdatareal alarmdatareal)
    {
        return toAjax(alarmdatarealService.insertAlarmdatareal(alarmdatareal));
    }

    /**
     * 修改报警实时记录
     */
    //@RequiresPermissions("business:alarmdatareal:edit")
    @Log(title = "报警实时记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Alarmdatareal alarmdatareal)
    {
        return toAjax(alarmdatarealService.updateAlarmdatareal(alarmdatareal));
    }

    /**
     * 删除报警实时记录
     */
    //@RequiresPermissions("business:alarmdatareal:remove")
    @Log(title = "报警实时记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable Long[] IDs)
    {
        return toAjax(alarmdatarealService.deleteAlarmdatarealByIDs(IDs));
    }

    @PostMapping("/restoration")
    public AjaxResult restoration(@RequestBody List<Alarmdatareal> alarmdatarealList) throws IOException {
        if (CollectionUtil.isEmpty(alarmdatarealList)) {
            return error("数据不能为空");
        }
        return toAjax(alarmdatarealService.restoration(alarmdatarealList));
    }
}
